import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { News } from '../../app/model/news';
import { NewsdetailPage } from '../newsdetail/newsdetail';
import { NewsProvider } from '../../providers/news/news';
import { Carousel } from '../../app/model/carousel';
import { CarouseldetailPage } from '../carouseldetail/carouseldetail';
import { ConfigProvider } from '../../providers/config/config';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
   cl:Array<Carousel>
   nl:Array<News>
   PICHOST:string;
   constructor(public navCtrl: NavController, 
    private newsService:NewsProvider,
    private configservice:ConfigProvider) {
      this.PICHOST=configservice.HOST+"/public/"
      this.initCarouselList();
      this.initNewsList();
  }

  initCarouselList(){
    this.cl=new Array();
    this.newsService.getCarouselList()
    .then((data:any)=>{
      this.cl=data;
    })
   }



  initNewsList(){
    this.nl=new Array();
    // for(let i=0;i<10;i++){
    // let n=new News();
    // n.title="标题"+i;
    // n.content="正文内容"+i;
    // this.nl.push(n);
    //   }

    this.newsService.getNewsList()
    .then((data:any)=>{
      this.nl=data;
    })

    }

    goToCarouselDetail(carousel:Carousel){
      this.navCtrl.push(CarouseldetailPage,{"carousel":carousel});
     }


    goToNewsDetail(news:News){
      this.navCtrl.push(NewsdetailPage,{"news":news});
    }



}
